package com.sooth.system.client.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dream.system.config.Page;
import com.sooth.common.core.domain.R;
import com.sooth.common.idempotent.annotation.RepeatSubmit;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.system.client.service.ISysClientService;
import com.sooth.system.client.view.SysClientBo;
import com.sooth.system.client.view.SysClientDto;
import com.sooth.system.client.view.SysClientVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 客户端管理
 *
 * @author Lion Li
 * @date 2023-06-18
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/client")
public class SysClientController extends BaseController {

    private final ISysClientService sysClientService;

    /**
     * 查询客户端管理列表
     */
    @SaCheckPermission("system:client:query")
    @GetMapping("/list")
    public R<Page<SysClientVo>> list(SysClientDto clientModel, Page page) {
        return R.ok(sysClientService.selectPage(clientModel, page));
    }

    /**
     * 获取客户端管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:client:query")
    @GetMapping("/query")
    public R<SysClientBo> query(@RequestParam Long id) {
        return R.ok(sysClientService.selectById(id));
    }

    /**
     * 新增客户端管理
     */
    @SaCheckPermission("system:client:add")
    @Log(title = "客户端管理", message = "新增客户端")
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> save(@RequestBody SysClientBo bo) {
        return toAjax(sysClientService.insert(bo));
    }

    /**
     * 修改客户端管理
     */
    @SaCheckPermission("system:client:edit")
    @Log(title = "客户端管理", message = "修改客户端")
    @RepeatSubmit()
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody SysClientBo bo) {
        return toAjax(sysClientService.updateById(bo));
    }

    /**
     * 删除客户端管理
     *
     * @param id 主键
     */
    @SaCheckPermission("system:client:remove")
    @Log(title = "客户端管理", message = "删除客户端")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(sysClientService.deleteById(id));
    }
}
